import React from 'react';
import {Provider, observer, inject} from 'mobx-react';
import {asyncComponent} from 'react-async-component';
import {Tools} from 'weaver-mobile';
import * as pageTypes from "../constants/OdocPageType";
import stores from "../stores/index";

const getLocaleLabel = Tools.getLocaleLabel;

//请使用异步组件
const pages = {
    OdocCusTab: asyncComponent({//自定义页签
        resolve: () => import("./odocCusTab/index")
    }),
}

@inject("odocPagesStore")
@observer
class OdocPage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            loadLang: false
        };
    }

    componentDidMount() {
        //加载多语言标签
        getLocaleLabel("odoc", () => {
            this.setState({loadLang: true})
        });
    }

    componentWillUnmount() {
        const {odocPagesStore} = this.props;
        odocPagesStore.resetStore();
    }

    componentWillMount() {
        const {workflowStores, comType, params, odocPagesStore} = this.props;
        odocPagesStore.setPropValue({
            workflowStores,
            comType,
            urlParams: params
        });
    }

    render() {
        const {odocPagesStore} = this.props;
        const {comType, urlParams} = odocPagesStore;
        const {OdocCusTab} = pages;
        let OdocPages = null;
        switch (comType) {
            case pageTypes.ODOC_LOG_LIST:
                OdocPages = <div>{JSON.stringify(urlParams)}</div>;
                break;
            case pageTypes.ODOC_CHANGE_ODOC_CUS_TAB:
                OdocPages = <OdocCusTab cusTabStore={odocPagesStore}/>;
                break;
            default:
                OdocPages = <div/>;
                break;
        }

        return OdocPages;
    }
}

export default class OdocPages2Workflow extends React.Component {
    render() {
        return (
            <Provider {...stores}>
                <OdocPage {...this.props}/>
            </Provider>
        );
    }
}